﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using TextAnalytics;

namespace TextAnalyticsTests
{
    [TestClass]
    public class TextSplitterTests
    {
        [TestMethod]
        public void TextSplitter_counts_only_distinct_words()
        {
            string text = @"The quick brown fox jumped over the fence. To be or not to be!";
            var result = TextSplitter.Default.Split(text);
            Assert.AreEqual(13, result.Words.Count);
        }

        [TestMethod]
        public void TextSplitter_counts_sentences_with_line_break()
        {

            string text1 = @"Related Articles
20/10/20 Some text";

            var result1 = TextSplitter.Default.Split(text1);

            Assert.AreEqual(1, result1.ParagraphCount);
            Assert.AreEqual(1, result1.SentenceCount);
        }


        [TestMethod]
        public void TextSplitter_counts_sentences_without_trailing_punctuation()
        {

            string text1 = @"Related Articles";

            var result1 = TextSplitter.Default.Split(text1);

            Assert.AreEqual(1, result1.ParagraphCount);
            Assert.AreEqual(1, result1.SentenceCount);
        }

        [TestMethod]
        public void TextSplitter_counts_comma_separated_numbers_as_one_word()
        {
            string text1 = @"200,000.";

            var result1 = TextSplitter.Default.Split(text1);

            Assert.AreEqual(1, result1.Words.Count);
            Assert.AreEqual(1, result1.ParagraphCount);
            Assert.AreEqual(1, result1.SentenceCount);
        }

        [TestMethod]
        public void TextSplitter_counts_one_paragraph_correctly()
        {
            string text1 = @"A large open workspace in Sofia, humming with the latest gadgets and a buzz of energy, is home to some of Southeast Europe's brightest entrepreneurial talent. ""The Roof,"" as it is known, is the collaborative office space utilised by 32 business startups funded by the accelerator programme Eleven.

";
            var result1 = TextSplitter.Default.Split(text1);

            Assert.AreEqual(2, result1.SentenceCount);
            Assert.AreEqual(1, result1.ParagraphCount);

            string text2 = @"Eleven takes its name from 11 kilometres per second -- the speed that is required for an object to escape the earth's orbit. Dilyan Dimitrov, a co-founder of Eleven, said the venture intends to help entrepreneurs escape the region and achieve global exposure. It is funded under a European Commission initiative that works to improve small- and medium-sized enterprises' access to finance and sustainable growth.

";
            var result2 = TextSplitter.Default.Split(text2);
            Assert.AreEqual(3, result2.SentenceCount);
            Assert.AreEqual(1, result2.ParagraphCount);
        }



        [TestMethod]
        public void TextSplitter_counts_two_paragraphs_correctly()
        {
            string sentence = @"A large open workspace in Sofia, humming with the latest gadgets and a buzz of energy, is home to some of Southeast Europe's brightest entrepreneurial talent. ""The Roof,"" as it is known, is the collaborative office space utilised by 32 business startups funded by the accelerator programme Eleven.

Eleven takes its name from 11 kilometres per second -- the speed that is required for an object to escape the earth's orbit. Dilyan Dimitrov, a co-founder of Eleven, said the venture intends to help entrepreneurs escape the region and achieve global exposure. It is funded under a European Commission initiative that works to improve small- and medium-sized enterprises' access to finance and sustainable growth.
";

            var result = TextSplitter.Default.Split(sentence);

            Assert.AreEqual(2, result.ParagraphCount);
        }

        [TestMethod]
        public void TextSplitter_counts_words_with_commas()
        {
            string sentence = @"People, animals and flowers.";

            var result = TextSplitter.Default.Split(sentence);

            Assert.AreEqual(4, result.Words.Count);
        }

        [TestMethod]
        public void TextSplitter_counts_two_sentences_correctly()
        {
            string sentence = @"The quick brown fox jumped over the fence. To be or not to be!";

            var result = TextSplitter.Default.Split(sentence);

            Assert.AreEqual(2, result.SentenceCount);
            Assert.AreEqual(1, result.ParagraphCount);
        }

        [TestMethod]
        public void TextSplitter_sentense_with_parentheses()
        {
            var sentence = "@The sentence has some text and (other text).";
            var result = TextSplitter.Default.Split(sentence);

            Assert.AreEqual(7, result.Words.Count);
        }

        [TestMethod]
        public void TextSplitter_counts_long_text_correctly()
        {
            var assembly = Assembly.GetExecutingAssembly();
            var resourceName = "TextAnalyticsTests.Resources.AdventuresOfSherlockHolmes.txt";

            string text;
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            using (StreamReader reader = new StreamReader(stream))
            {
                text = reader.ReadToEnd();
            }
            var result = TextSplitter.Default.Split(text);
            var words = result.Words.Count;
            var mm = 5;
        }
    }
}
